<template>
	<view class="order">
		<view class="orderinfo" :style="{height:screenHeight+'px'}">
			<scroll-view scroll-y="true" class="scroll">
				<view class="consignee_info" v-if="Object.keys(currentAddress).length">
					<view class="icon">
						<uni-icons type="location" size="30" color="#ff557f"></uni-icons>
					</view>
					<view class="consignee_info_detail">
						<view class="" style="margin-bottom: 10rpx;">
							<text style="font-size: 40rpx;margin-right: 20rpx;">{{getCurrentAdress.receive_name}}</text>
							<text style="font-size: 34rpx; color: #ccc;">{{getCurrentAdress.phone}}</text>
						</view>
						<view class="address_detail">
							<view class="address_detail_info">
								{{getCurrentAdress.detail_address}}
							</view>
						</view>
					</view>
					<view class="icon" @click="hanleToAddress">
						<uni-icons type="forward" size="18" color="#d1d1d1"></uni-icons>
					</view>
				</view>
				<view class="consignee_info" v-else>
					<view class="">
						<uni-icons type="person-filled" size="30"></uni-icons>
					</view>
					<view class="consignee_info_detail">
						<view class="" style="font-size: 32rpx;">
							收件人信息
						</view>
						<view class="consignee_info_detailPay" @click="hanleToAddress">
							<text>请选择购买人信息</text>
							<uni-icons type="forward" size="18" color="#000000"></uni-icons>
						</view>
					</view>
				</view>
				<!-- 商品 -->
				<view class="goods_info" v-for="item in pickGoods" :key="item.product_id">
					<view class="goods_img">
						<image :src="item.product_img||item.cover_img" mode=""></image>
					</view>
					<view class="goods_detail">
						<view class="" style="font-size: 34rpx;font-weight: 560;">
							{{item.product_title||item.title}}
						</view>
						<view class="goods_detail_two">
							<text style="font-size: 30rpx;">￥{{item.amount}}</text>
							<text style="color: #ccc;font-size: 40rpx;">x{{item.buy_num||1}}</text>
						</view>
						<view class="goods_detail_three">
							共{{item.buy_num||1}}件&nbsp;小计:<text
								style="color: #FF0000;">￥{{item.amount*item.buy_num || item.amount}}</text>
						</view>
					</view>
				</view>
				<view class="preferential">
					<view class="preferential_cop" @click="hanleToCoupons">
						<text>优惠卷:
							<text style="color: #ff0000;margin-left: 40rpx;">{{couponsPrice.price||0}}元</text></text>
						<uni-icons type="forward" size="18"></uni-icons>
					</view>
					<view class="preferential_cop" style="border: 0px">
						<text>运费</text>
						<text style="color: #FF0000;">￥0</text>
					</view>
				</view>
				<view class="note">
					<view style="font-size: 34rpx;">备注</view>
					<view class="note_info">
						选填：<input type="text" class="beizhu" placeholder="建议与商家协商好"
							placeholder-style="color:rgb(189, 189, 189);fontSize: 20rpx;" />
					</view>
				</view>
				<view class="">

					<mp-html :content="strings" />
				</view>
			</scroll-view>

		</view>


		<view class="Payorder">
			<view class="Payorder_detail">
				<text v-if="couponsPrice.price">实付金额：<text class="price">￥{{pickTotal-couponsPrice.price}}<del 
							style="font-size: 14px;color: #C4C6C9;margin-left: 14rpx;">{{pickTotal}}</del></text></text>

				<text v-else>实付金额：<text class="price">￥{{pickTotal}}</text></text>
				<view class="Payorder_detail_btn" @click="handleToOrder">
					提交订单
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		mapGetters,
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				screenHeight: 0,
				Ordertoken: '',
				strings: ``
			}
		},
		onLoad() {
			this.getscreenHeight()
			// console.log(this.getProductId)

		},
		onBackPress(event) {
			uni.switchTab({
				url: '../cart/cart'
			})
			return true;
		},
		computed: {
			currentAddress() {
				return this.$store.state.m_user.currentAddress
			},
			pickGoods() {
				return JSON.parse(JSON.stringify(this.$store.state.m_cart.pickGoods))
			},
			getCurrentAdress() {
				return this.$store.state.m_user.currentAddress
			},
			...mapGetters('m_cart', ['pickTotal', 'getProductId', ]),
			...mapState('m_user', ['currentAddressId', 'couponsPrice'])
		},
		methods: {
			// #ifdef APP
			getscreenHeight() {
				let res = uni.getSystemInfoSync()
				this.screenHeight = res.screenHeight - res.windowTop - res.statusBarHeight - 100
			},
			// #endif
			// #ifdef H5 || MP-WEIXIN    
			getscreenHeight() {
				let res = uni.getSystemInfoSync()
				this.screenHeight = res.screenHeight - res.windowTop - res.statusBarHeight - 56
			},
			// #endif


			hanleToAddress() {
				uni.navigateTo({
					url: '../address/address'
				})
				this.$store.commit('m_user/updateaddflag', true)
			},
			hanleToCoupons() {
				uni.navigateTo({
					url: '../coupons/coupons'
				})
			},
			handleToOrder() {
				uni.$http.get('/order-server/api/order/v1/get_token').then(res => {
					this.Ordertoken = res.data.data
					console.log(this.Ordertoken)
					uni.$http.post('/order-server/api/order/v1/confirm', {
						"coupon_record_id": -1,
						"product_ids": this.getProductId,
						"pay_type": "ALIPAY",
						"client_type": "H5",
						"address_id": this.currentAddressId,
						"real_pay_amount": this.pickTotal,
						"token": this.Ordertoken
					}).then(res => {
						console.log(res)
						//将接口返回的Form表单显示到页面
						document.querySelector('body').innerHTML = res.data;
						//调用submit 方法
						document.forms[0].submit()
						// this.strings = res.data
						// console.log(this.strings)
					})
				})

			},
		}
	}
</script>

<style scoped>
	.beizhu {
		color: #000000;
		width: 80%;
	}

	* {
		box-sizing: border-box;
	}

	.scroll {
		height: 100%;
	}

	.icon {
		display: flex;
		align-items: center;
	}

	.address_detail {
		display: flex;
		align-items: center;
		height: 130rpx;
	}

	.address_detail_info {
		height: 100%;
		width: 100%;
	}

	.order {
		background: linear-gradient(to top, #daeaff 50%, #ff557f);
		/* background-color: #ff557f; */
		padding: 0 20rpx;
		padding-top: 20rpx;
	}

	.orderinfo {
		padding-bottom: 20rpx;
	}

	.consignee_info {
		display: flex;
		height: 200rpx;
		border-radius: 10rpx;
		padding: 20rpx;
		background-color: #FFFFFF;
	}

	.consignee_info_detail {
		flex: 1;
	}

	.consignee_info_detailPay {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		font-size: 20rpx;
		color: #a5a5a5;
		height: 120rpx;
	}

	.goods_info {
		display: flex;
		height: 250rpx;
		background-color: #ffffff;
		border-radius: 10rpx;
		margin-top: 20rpx;
		padding: 20rpx;
	}

	.goods_img {
		height: 100%;
		width: 30%;
		border-radius: 20rpx;
	}

	.goods_img image {
		width: 100%;
		height: 100%;
		display: block;
	}

	.goods_detail {
		height: 100%;
		flex: 1;
		padding-left: 20rpx;
		padding-top: 10rpx;
	}

	.goods_detail_two {
		display: flex;
		margin-top: 20rpx;
		justify-content: space-between;
	}

	.goods_detail_three {
		margin-top: 20rpx;
		display: flex;
		justify-content: flex-end;
		font-size: 34rpx;
	}

	.preferential {
		background-color: #FFFFFF;
		border-radius: 10rpx;
		margin-top: 20rpx;
		font-size: 34rpx;
		padding: 0 20rpx;
	}

	.preferential_cop {
		display: flex;
		height: 60rpx;
		padding: 40rpx 0;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #C4C6C9;
	}

	.note {
		margin-top: 20rpx;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		height: 150rpx;
		padding: 20rpx;
	}

	.note_info {
		margin-top: 20rpx;
		display: flex;
		color: #CCCCCC;
	}

	.Payorder {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: #FFFFFF;
		height: 50px;
	}

	.Payorder_detail {
		height: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 30rpx;
	}

	.price {
		color: #ff0000;
		font-size: 40rpx;
	}

	.delprice {
		font-size: 26rpx;
		color: #ccc;
		margin-left: 10rpx;

	}

	.Payorder_detail_btn {
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #ff557f;
		color: #fff;
		padding: 12rpx 40rpx;
		border-radius: 40rpx;
	}
</style>
